const app = getApp();
Component({
	options: {
		styleIsolation: 'apply-shared'
	},


	/**
	 * 组件的属性列表
	 */
	properties: {
         'skulist':{type:Array},
				 'tips':{type:Boolean,value:false},
				 'myinfo':{type:Object}
	},

	/**
	 * 组件的初始数据
	 */
	data: {
	},

	observers: {
	},

	/**
	 * 组件的方法列表
	 */
	methods: {
		collectChange:function (e) {
			let id = e.currentTarget.dataset.id;
			let index = e.currentTarget.dataset.index;
			app.func.getPromise('/product/choosestatus/' + id)
				.then(([code, res]) => {
					res.data.status == 0 ? this.addChoose(id,index) : this.clearChoose(id,index);
				})
		},
		addChoose:function (e) {
			let id = e.currentTarget.dataset.id;
			let index = e.currentTarget.dataset.index;
			app.func.getPromise('/addcart/'+id)
				.then(([code, res]) => {
					if(code == 200){
						app.func.toastPromise('成功加入优选','none',500);
						this.triggerEvent("collectChange",{index:index,value:1})
					}else{
						app.func.toastPromise(res.message);
					}
				})
		},
		clearChoose:function (e) {
			let id = e.currentTarget.dataset.id;
			let index = e.currentTarget.dataset.index;
			app.func.getPromise('/delcart/'+id)
				.then(([code, res]) => {
					if(code == 200){
						app.func.toastPromise('已移除优选','none',500);
						this.triggerEvent("collectChange",{index:index,value:0})
					}else{
						app.func.toastPromise(res.message);
					}
				})
		},


		skuIntro:function(e){
		  let id = e.currentTarget.dataset.id;
			wx.navigateTo({
				url: '/pages/index/productdetail/product-description/product-description?id=' + id
			})
		},


		productdetail: function (e) {
			var id = e.currentTarget.dataset.id;
			wx.navigateTo({
				url: '/pages/index/productdetail/productdetail?id=' + id
			})
		},

		login: function () {
			// console.log('登录');
			wx.switchTab({
				url: '/pages/about/about'
			})
		},

		addonshopbuy: function (e) {
			var id = e.currentTarget.dataset.id;
			//旧的跳转
		/**
		 * wx.navigateTo({
				url: '/pages/gifts/pages/order/order?id=' + id
			})
		 *  */	
		wx.navigateTo({
			url: '/pages/cartshop/payif/payif?skuid=' + id
	})
		},

		attestation:function(){
			wx.navigateTo({
				url:'/pages/auth/preattestation/preattestation'
			})
		},


	}
})
